<?php
declare(strict_types=1);

namespace LowCode\Naive;

use LowCode\Naive;
use LowCode\Support\JsExp;
use LowCode\Traits\Props\HasColor;

/**
 * NIcon
 * @method static static make(mixed $children = null) NIcon
 */
class Icon extends Naive
{

    use HasColor;

    protected ?Naive $wrapper = null;

    /**
     * @param mixed|null $children
     */
    public function __construct(mixed $children = null)
    {
        parent::__construct();
        $this->children($children);
    }

    /**
     * 设置图标名称
     * @param string $component
     * @return $this
     */
    public function component(string $component): static
    {
        return $this->prop("component",$component);
    }


    /**
     * 设置图标大小
     * @param int|string|JsExp $size
     * @return $this
     */
    public function size(int|string|JsExp $size): static
    {
        return $this->prop("size", $size);
    }

    /**
     * 设置图标深度
     * @param int|string|JsExp $depth 1 | 2 | 3 | 4 | 5
     * @return $this
     */
    public function depth(int|string|JsExp $depth = 1): static
    {
        return $this->prop("depth", $depth);
    }

    /**
     * @param int|JsExp $size
     * @param callable|null $callable
     * @return $this
     */
    public function wrapper(int|JsExp $size = 24 ,callable $callable = null): static
    {
        $this->wrapper = new IconWrapper();
        $this->wrapper->size($size);
        if ($callable){
            $this->wrapper->children($callable);
        }
        return $this;
    }

    /**
     * @return array
     */
    public function toArray(): array
    {
        $wrapper = $this->wrapper;
        if ($wrapper){
            $this->wrapper = null;
            return $wrapper->children($this)->toArray();
        }
        return parent::toArray();
    }
}
